package com.example.wangda.smart_home_android_v12;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.util.Log;
import android.widget.Toast;

import java.util.List;

import static android.content.ContentValues.TAG;

/**
 * Created by wangda on 2017/11/17.
 */

public class WifiStateBroadCast extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent){
        //获取manager
        ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        //获取Wifi状态
       // NetworkInfo.State state = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
        NetworkInfo mNetworkInfo = connectivityManager.getActiveNetworkInfo();

        if(mNetworkInfo == null){
            Toast.makeText(context, "网络已断开连接", Toast.LENGTH_SHORT).show();
         //   MainActivity.Log_out("网络已断开连接");
            GlobalData.SetWifiConnectSta(UnConnect);
        }else if(mNetworkInfo != null){
            Toast.makeText(context, "网络已连接", Toast.LENGTH_SHORT).show();
           // MainActivity.Log_out("网络已连接");
            GlobalData.SetWifiConnectSta(oneConnect);
        }
    }

    public static final int UnConnect = 0;
    public static final int connect = 1;
    public static final int oneConnect = 2;

}


